#ifndef _TFT_ARDUINO_MEGA_H_
#define _TFT_ARDUINO_MEGA_H_


#define LCD_BL_DDR		DDRL
#define LCD_BL_PORT		PORTL
#define LCD_BL_PIN		PORTL6

#define LCD_CTRL_DDR	DDRL

#define LCD_RS_PORT		PORTL
#define LCD_RS_PIN		PORTL2

#define LCD_CS_PORT		PORTL
#define LCD_CS_PIN		PORTL1

#define LCD_WR_PORT		PORTL
#define LCD_WR_PIN		PORTL3

#define LCD_RD_PORT		PORTL
#define LCD_RD_PIN		PORTL4

#define LCD_RST_PORT	PORTL
#define LCD_RST_PIN		PORTL5

#define LCD_DBH_DDR		DDRA
#define LCD_DBH_PORT	PORTA
#define LCD_DBH_PINP	PINA

#define LCD_DBL_DDR		DDRC
#define LCD_DBL_PORT	PORTC
#define LCD_DBL_PINP	PINC


#define TP_CS_DDR	  	DDRD
#define TP_CS_PORT		PORTD
#define TP_CS_PIN		PORTD7

#define SD_CS_DDR		DDRL
#define SD_CS_PORT		PORTL
#define SD_CS_PIN		PORTL0

//PORT deifinition for Touchpanel
//SPI configuration (Platform dependent)
#define SPI_DDR		DDRB
#define SPI_PORT 	PORTB
#define SPI_SS		PORTD7
#define DD_MOSI		PORTB2
#define DD_MISO		PORTB3
#define DD_SCK		PORTB1




#define sbi(port,bitnum)		port |= _BV(bitnum)
#define cbi(port,bitnum)		port &= ~(_BV(bitnum))

#define RSTOUT sbi(LCD_CTRL_DDR, LCD_RST_PIN)
#define RST0 cbi(LCD_RST_PORT,LCD_RST_PIN)
#define RST1 sbi(LCD_RST_PORT,LCD_RST_PIN)

#define RDOUT sbi(LCD_CTRL_DDR, LCD_RD_PIN)
#define RD0 cbi(LCD_RD_PORT,LCD_RD_PIN)
#define RD1 sbi(LCD_RD_PORT,LCD_RD_PIN)




#define CS0 cbi(LCD_CS_PORT,LCD_CS_PIN)
#define CS1 sbi(LCD_CS_PORT,LCD_CS_PIN)
#define RS0 cbi(LCD_RS_PORT,LCD_RS_PIN)
#define RS1 sbi(LCD_RS_PORT,LCD_RS_PIN)
#define WR0 cbi(LCD_WR_PORT,LCD_WR_PIN)
#define WR1 sbi(LCD_WR_PORT,LCD_WR_PIN)
#define SD0 cbi(SD_CS_PORT, SD_CS_PIN)
#define SD1 sbi(SD_CS_PORT, SD_CS_PIN)
#define TP0	cbi(TP_CS_PORT, TP_CS_PIN)
#define TP1 sbi(TP_CS_PORT, TP_CS_PIN)

//latch is not used in Arduino mega, true 16-bit mode is used instead

#define LATCH1  
#define LATCH0  
#define LATCHOUT


#define DATAIN		LCD_DBH_DDR = 0; \
							LCD_DBL_DDR = 0
#define DATAOUT		LCD_DBH_DDR = 0xff; \
							LCD_DBL_DDR = 0xff

#define LCD_BL_OFF()	LCD_BL_DDR  |=  (1<<LCD_BL_PIN); \
						sbi(LCD_BL_PORT, LCD_BL_PIN)
#define LCD_BL_ON()		LCD_BL_DDR  |=  (1<<LCD_BL_PIN); \
						cbi(LCD_BL_PORT, LCD_BL_PIN)



#define LCD_SET_DATH(x)	LCD_DBH_PORT = x


#define LCD_SET_DATL(x)	LCD_DBL_PORT = x



#endif
